package com.mzj.saas.sdk.pay;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.mzj.saas.sdk.pay.alipay.AliPayRequest;
import com.mzj.saas.sdk.pay.callback.AliPayCallback;
import com.mzj.saas.sdk.pay.callback.WxPayCallback;
import com.mzj.saas.sdk.pay.vo.AliPay;
import com.mzj.saas.sdk.pay.vo.WxPay;
import com.mzj.saas.sdk.pay.wxpay.WxPayRequest;

/**
 * 
 * 测试用例
 * @author hp
 *
 */
public class Test {

	public static void main(String[] args) throws Exception{

		//微信支付
		//WxPay wxpay = new WxPay(appId, mchId, outTradeNo, attac, totalFree, body, mchApiKey, openid, callbackUrl, unifiedApi, spbillCreateIp);
		WxPay wxpay = new WxPay();
		WxPayRequest wxPayRequest = new WxPayRequest(wxpay);
		//Map<String, Object> appResult = wxPayRequest.unifiedByApp();
		Map<String, Object> miniResult = wxPayRequest.unifiedByMini();
		
		
		//微信支付回调
		String mchApiKey = null;
		HttpServletRequest request = null;
		HttpServletResponse response = null;
		WxPayCallback wxpayCallback = new WxPayCallback(mchApiKey,request,response);
		//签名校验
		Map<String,String> wxResult =  wxpayCallback.verifyResult();
		if(wxResult == null) {
			//检验失败
			wxpayCallback.resultFail();
			return;
		}
		//相关业务处理
		wxpayCallback.resultSuccess();
		
		
		//支付宝支付
		//AliPay = alipay = new AliPay(appId, privateKey, publicKey, outTradeNo, totalAmount, subject, productCode, passbackParams, notifyUrl);
		AliPay  alipay = new AliPay();
		AliPayRequest aliRequet = new AliPayRequest(alipay);
		Map<String, Object> body = aliRequet.appPay();
		
		
		//支付宝支付回调
		String appid = null;
		String publicKey = null;
		//HttpServletRequest request = null;
		//HttpServletResponse response = null;
		AliPayCallback alipayCallback = new AliPayCallback(appid,publicKey,request,response);
		Map<String,String> aliResult = alipayCallback.verifyResult();
		if(aliResult == null) {
			//检验失败
			alipayCallback.resultFail();
			return;
		}
		//tradeStatus=TRADE_SUCCESS(付款成功)
		//tradeStatus=TRADE_FINISHED(交易完成,无需处理，直接返回成功)
		//tradeStatus=TRADE_CLOSED(交易关闭,无需处理，直接返回成功)
		if(aliResult.get("tradeStatus").equals("TRADE_FINISHED") || aliResult.get("tradeStatus").equals("TRADE_CLOSED") ) {
			alipayCallback.resultSuccess();
			return;
		}
		
		if(aliResult.get("tradeStatus").equals("TRADE_SUCCESS")) {
			//相关业务处理
			
		}
		alipayCallback.resultSuccess();
		return;
	}

}
